from common.base_model import BasicModelMixin, CompanyMixin, \
    CreateWithShortNameMixin, UpdateWithShortNameMixin, DeleteMixin
from exts import db
from common import constant


class Customer(BasicModelMixin, db.Model, CompanyMixin,
               CreateWithShortNameMixin, UpdateWithShortNameMixin,
               DeleteMixin):
    __tablename__ = 'customer'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(constant.MIDDLE_DB_STR_LEN), nullable=False)
    short_name = db.Column(db.String(constant.MIDDLE_DB_STR_LEN))

    customer_type = db.Column(db.Integer, default=constant.CustomerType.CLIENT.value)
    discount = db.Column(db.DECIMAL(20, constant.COMMON_DECIMAL), default=1, server_default='1')  # 折扣
    address = db.Column(db.String(constant.LONG_DB_STR_LEN))
    contact = db.Column(db.String(constant.LONG_DB_STR_LEN))  # 联系人
    phone = db.Column(db.String(20))
    email = db.Column(db.String(constant.MIDDLE_DB_STR_LEN), nullable=True)

    __table_args__ = (
        db.UniqueConstraint('name', 'company_id'),
    )
